﻿namespace Comdiv.QWeb.Utils.LogicalExpressionLanguage {
	public class EqualNode : LogicalExpressionNode {
		public string FirstLiteral { get; set; }
		public string SecondLiteral { get; set; }

		protected override bool internalEval(ILogicTermSource source) {
			if (FirstLiteral.StartsWith("$") && SecondLiteral.StartsWith("$")) {
				return source.value(FirstLiteral.Substring(1)) == source.value(SecondLiteral.Substring(1));
			}
			if (FirstLiteral.StartsWith("$") && !SecondLiteral.StartsWith("$")) {
				return source.value(FirstLiteral.Substring(1)) == source.value(SecondLiteral);
			}
			if (!FirstLiteral.StartsWith("$") && SecondLiteral.StartsWith("$")) {
				return source.value(FirstLiteral) == source.value(SecondLiteral.Substring(1));
			}
			return source.get(FirstLiteral) == source.get(SecondLiteral);
		}
	}
}